package com.example.toast;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
/**
 * 五种不同的toast
 * @author ZSL
 * @version 2014-07-03 21:21:53
 */
public class MainActivity extends Activity implements OnClickListener{
	private Button bt_one;
	private Button bt_two;
	private Button bt_three;
	private Button bt_four;
	private Button bt_five;
	private Toast toast;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		init();
		bt_one.setOnClickListener(this);
		bt_two.setOnClickListener(this);
		bt_three.setOnClickListener(this);
		bt_four.setOnClickListener(this);
		bt_five.setOnClickListener(this);
		
		
	}
	/**
	 * 初始化
	 */
	public void init(){
		bt_one=(Button) findViewById(R.id.bt_one);
		bt_two=(Button) findViewById(R.id.bt_two);
		bt_three=(Button) findViewById(R.id.bt_three);
		bt_four=(Button) findViewById(R.id.bt_four);
		bt_five=(Button) findViewById(R.id.bt_five);
		
		
	}
	
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.bt_one:
		{
			Toast.makeText(this, "普通的Toast", Toast.LENGTH_SHORT).show();
		}
		break;
		case R.id.bt_two:
		{
			toast=Toast.makeText(this, "有位置的Toast", Toast.LENGTH_SHORT);
			toast.setGravity(Gravity.CENTER, 0, 0);
			toast.show();
			
		}
		break;
		case R.id.bt_three:
		{
			toast=Toast.makeText(getApplicationContext(), "有图片的Toast", Toast.LENGTH_SHORT);
			LinearLayout layout=(LinearLayout) toast.getView();
			ImageView imageView=new ImageView(getApplicationContext());
			imageView.setImageDrawable(getResources().getDrawable(R.drawable.wallpaper_field_small));
			layout.addView(imageView);
			toast.setGravity(Gravity.CENTER, 50, -100);
			toast.show();
		}
		break;
		case R.id.bt_four:
		{
			LayoutInflater inflater=getLayoutInflater();
			View view2=inflater.inflate(R.layout.toast_item,null);
			toast=new Toast(getApplicationContext());
			toast.setGravity(Gravity.CENTER, 0, 0);
			toast.setView(view2);
			toast.show();
		}
		break;
		case R.id.bt_five:
		{
			LayoutInflater inflater=getLayoutInflater();
			View view2=inflater.inflate(R.layout.toast_item,null);
			AlertDialog.Builder builder=new AlertDialog.Builder(this);
			builder.setView(view2);
			AlertDialog dialog=builder.create();
			dialog.show();
		}
		break;
		
		default:
			break;
		}
	}

}
